<?php
/**
 * 房源拍卖状态 补救
 */

namespace app\crontab\controller\once;


use custom\Mongo;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class HouseAuctionStatus extends Command {

    protected function configure() {
        $this->setName('HouseAuctionStatus');
    }

    protected function execute(Input $input, Output $output) {
        $this->initial();
    }

    protected function initial() {
        // 获取所有未完结的拍卖信息
        $where[] = ['auction_status', 'in', [1, 2]];
        $where[] = ['source_type', '=', 2];
        $data = db('house_auction')->field('id,source_id')->where('auction_status', 'in', [1, 2])->select();
        $houseIds = array_column($data, 'source_id');
        $data = array_column($data, null, 'source_id');
        $mongo = Mongo::getInstance();
        $c = $mongo->select('house_ali', ['house_id' => ['$in' => $houseIds], 'auction_status' => ['$gt' => '2']], []);
        $t = $s = 0;
        foreach ($c as $key => $value) {
            $upData = [];
            $t++;
            $value = (array)$value;
            $upData['auction_status'] = $value['auction_status'];
            !empty($value['final_price']) && $upData['deal_time'] = $value['deal_time'];
            !empty($value['final_price']) && $upData['final_price'] = moneyFormat($value['final_price'], 1);
            !empty($value['enroll_num']) && $upData['enroll_num'] = $value['enroll_num'];
            !empty($value['remind_num']) && $upData['deal_time'] = $value['remind_num'];

            if (db('house_auction')->where('id', $data[$value['house_id']]['id'])->update($upData)) {
                $s++;
            }
        }
        echo "t:{$t}||s:{$s}";
    }
}